package jalgebrava.group.properties;

import jalgebrava.group.Group;
import jalgebrava.group.Subgroup;
import jalgebrava.group.groups.AutomorphismGroupFactory;

import jalgebrava.group.morphisms.Automorphism;

public class GroupProperties {
	
	public static final <G> GroupProperty<G, Boolean> isAbelian(Group<G> group) {
		return new GroupProperty<G, Boolean>("Group.isAbelian", group) {
			@Override
			public Boolean compute(Group<G> g) {
				for (G x: g) {
					for (G y: g) {
						if (!g.equals(g.mul(x,y),g.mul(y,x))) {
							return false;
						}
					}
				}
				return true;
			}			
		};
	}
	
	public static final <G> GroupProperty<G, Boolean> isCyclic(Group<G> group) {
		return new GroupProperty<G, Boolean>("Group.isCyclic", group) {
			@Override
			public Boolean compute(Group<G> g) {
				for (G x: g) {
					Subgroup<G> genX = Subgroup.generate(g.element(x));
					if (genX.size() == g.size()) {
						return true;
					}
				}
				return false;
			}			
		};
	}
	
	public static final <G> GroupProperty<G, Group<Automorphism<G>>> automorphismGroup(Group<G> group) {
		return new GroupProperty<G, Group<Automorphism<G>>>("Group.automorphismGroup", group) {

			@Override
			public Group<Automorphism<G>> compute(Group<G> g) {
				return AutomorphismGroupFactory.mk(g);
			}
			
		};
	}
	
}
